package socket.before;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.net.Socket;

public class Client {

	public static void main(String[] args) throws Exception {
		t1();
	}

	public static void t1() throws Exception, IOException {
		Socket socket = new Socket("127.0.0.1", 8989);
		socket.setSoTimeout(2000);
		OutputStream os = socket.getOutputStream();
		os.write("你好io".getBytes());
		os.flush();
		Reader reader = new InputStreamReader(socket.getInputStream());
		char chars[] = new char[64];
		int len;
		StringBuffer sb = new StringBuffer();
		while ((len = reader.read(chars)) != -1) {
			sb.append(new String(chars, 0, len));
		}
		System.out.println("from server: " + sb);
		os.close();
		reader.close();
		socket.close();
	}

}
